package com.ly.live.aliyunlive.service;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.ly.live.aliyunlive.controller.LiveOssCallbackRequest;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
public class LiveCallbackServiceImpl {

    public void saveOssCallback(Map<String, Object> params) {
        if (params.containsKey("domain") && params.containsKey("stream")
                && params.containsKey("app") && params.containsKey("uri")
                && params.containsKey("duration") && params.containsKey("start_time")
                && params.containsKey("stop_time")) {
            JSONObject jsonObject = new JSONObject(params);
            LiveOssCallbackRequest liveOssCallbackRequest =
                    JSON.toJavaObject(jsonObject, LiveOssCallbackRequest.class);
            liveOssCallbackRequest.setPhone(liveOssCallbackRequest.getStream().replace("pliveStream",""));
            //todo  保存到数据库
        }
    }
}
